package com.ka.component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.widget.EditText;

public class PasswordValidation extends IFieldValidation {

	private EditText pass;

	public PasswordValidation(EditText password) {

		pass = password;
		require = false;

	}

	public PasswordValidation(EditText password, Boolean req) {

		pass = password;
		require = req;

	}

	@Override
	public MessageValidate validate() {

		MessageValidate message = new MessageValidate();

		String text = pass.getText().toString();

		if (!StringUtils.checkInvalidString(text) && require) {
			message.addErrorMessage("Invaid password.");
			return message;
		}

		if (!StringUtils.checkMaxValidString(text)) {
			message.addErrorMessage("Password overflow size (1000).");
			return message;
		}

		Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
		Matcher m = p.matcher(text);
		boolean b = m.find();

		if (b) {
			message.addErrorMessage("Password contain violation character.");
		}

		return message;

	}

}
